from manim import *

class booleanOperation(Scene):
    def construct(self):
        set_a = Ellipse(width=4, height=5,color=BLUE, fill_opacity=0.5)
        set_b = set_a.copy().set_color(RED).shift(RIGHT)
        set_text = MarkupText("Boolean Opeeration").next_to(set_a, UP*3)
        set_group = Group(set_a, set_b, set_text).move_to(LEFT*3)

        self.play(FadeIn(set_group))
        self.wait()
        
        # 交集
        set_intersection = Intersection(set_a, set_b, color=GREEN, fill_opacity=0.5)
        self.play(set_intersection.animate.scale(0.25).move_to(RIGHT*4 + UP *2.5))
        set_i_text = Text("Intersection", font_size=20).next_to(set_intersection, UP)
        self.play(FadeIn(set_i_text))
        self.wait()
        
        # 合集
        set_u = Union(set_a, set_b, color=ORANGE, fill_opacity=0.5)
        set_u_text = Text("Union", font_size=20).next_to(set_u, UP)
        self.play(set_u.animate.scale(0.25).move_to(RIGHT*4))
        set_u_text.next_to(set_u, UP)
        self.play(FadeIn(set_u_text))
        self.wait()
        
        # 互斥集
        set_e = Exclusion(set_a, set_b, color=YELLOW, fill_opacity=0.5)
        e_text = Text("Exclusion", font_size=20)
        self.play(set_e.animate.scale(0.25).move_to(RIGHT*4 + DOWN *2.5))
        e_text.next_to(set_e, UP)
        self.play(FadeIn(e_text))
        self.wait()
        
        # 差集
        set_d = Difference(set_a, set_b, color=PINK, fill_opacity=0.5)
        d_text = Text("Difference", font_size=20)
        self.play(set_d.animate.scale(0.25).move_to(RIGHT*2))
        d_text.next_to(set_d, UP)
        self.play(FadeIn(d_text))
        self.wait()